﻿#define _CRT_SECURE_NO_WARNINGS 1
include<stdio.h>

int* findDisappearedNumbers(int* nums, int numsSize, int* returnSize) {
    int* findDisappearedNumbers(int* nums, int numsSize, int* returnSize) {
        for (int i = 0; i < numsSize; i++) {
            int x = (nums[i] - 1) % numsSize;
            nums[x] += numsSize;
        }
        int* ret = malloc(sizeof(int) * numsSize);
        *returnSize = 0;
        for (int i = 0; i < numsSize; i++) {
            if (nums[i] <= numsSize) {
                ret[(*returnSize)++] = i + 1;
            }
        }
        return ret;
    }

}

//给定一棵二叉树，你需要计算它的直径长度。
// 一棵二叉树的直径长度是任意两个结点路径长度中的最大值。这条路径可能穿过也可能不穿过根结点。
//
//
//
//示例:
//给定二叉树
//
//1
/// \
//2   3
/// \
//4   5
//返回 3, 它的长度是路径[4, 2, 1, 3] 或者 [5, 2, 1, 3]。
int heightOfTree(struct TreeNode* root, int* max)
{
    if (!root) return 0;
    int left = heightOfTree(root->left, max);
    int right = heightOfTree(root->right, max);
    if (left + right > *max)
        *max = left + right;
    return (left > right ? left : right) + 1;
}
int diameterOfBinaryTree(struct TreeNode* root) {
    int max = 0;
    heightOfTree(root, &max);
    return max;
}